package com.mframe.util;

import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.commons.beanutils.BeanUtils;
/**
 *Title: 常用自定义函数 <br/>
 *Description: <br/>
 *Copyright (c) 2011 ICSS HaiSheng Co.,Ltd <br/>
 *All Rights Reserved<br/>
 *author youjx <br/>
 *Create Date:2011-05-11 <br/>
 *Modify By:修改人 <br/>
 *Modify Date:修改日期 <br/>
 *Remark:修改说明<br/>
 **/
@SuppressWarnings("unchecked")
public class Utils {
	/**
	 * function:判断字符串是否为空<br/>
	 * remark:判断字符串是否为空
	 * 
	 * @param expression
	 *            字符串
	 * @return 是/否字符串
	 **/
	public static boolean isNull(String expression) {
		if (expression == null || expression.length() == 0)
			return true;
		return false;
	}

	/**
	 * function:判断字符串是否为浮点型字符串<br/>
	 * remark:判断字符串是否为空
	 * 
	 * @param expression
	 *            字符串
	 * @return 是/否浮点型
	 **/
	public static boolean isFloat(String expression) {
		if (isNull(expression))
			return false;

		try {
			Float.valueOf(expression);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}

	/**
	 * function:判断字符串是否为整型字符串<br/>
	 * remark:
	 * 
	 * @param expression
	 *            字符串
	 * @return 是/否整型
	 **/
	public static boolean isInteger(String expression) {
		if (isNull(expression))
			return false;

		try {
			Integer.valueOf(expression);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	}

	/**
	 * function:字符串右边去空格<br/>
	 * remark:
	 * 
	 * @param expression
	 *            字符串
	 * @return 右去空格后的字符串
	 **/

	public static String rTrim(String expression) {
		int i = 0;

		if (expression == null || expression.length() == 0)
			return "";

		for (i = expression.length(); i >= 0; i--) {
			if (expression.charAt(i - 1) != ' ')
				break;
		}

		if (i == 0)
			return "";
		else
			return expression.substring(0, i);
	}

	/**
	 * function:字符串左边去空格<br/>
	 * remark:
	 * 
	 * @param expression
	 *            字符串
	 * @return 去左空格后的字符串
	 **/
	public static String lTrim(String expression) {
		int i = 0;
		if (expression == null || expression.length() == 0)
			return "";
		for (i = 0; i < expression.length(); i++) {
			if (expression.charAt(i) != ' ')
				break;
		}
		return expression.substring(i);
	}

	/**
	 * function:判断字符串是否为数字型字符串<br/>
	 * remark:
	 * 
	 * @param expression
	 *            字符串
	 * @return 是否数字型
	 **/
	public static boolean isNumeric(String expression) {
		if (isFloat(expression) || isInteger(expression))
			return true;

		return false;
	}

	/**
	 * function：得到按指定格式的系统当前时间<br/>
	 * remark:
	 * 
	 * @param dateFormat
	 *            日期格式
	 * @return 格式化的日期字符串
	 **/
	public static String getSysDate(String dateFormat) {
		if (dateFormat == null || "".equals(dateFormat)) {
			dateFormat = "yyyy-MM-dd HH:mm:ss";
		}
		Calendar date = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		String dateStr = sdf.format(date.getTime());
		return dateStr;
	}

	/**
	 * function：得到按指定格式的系统当前时间<br/>
	 * remark:
	 * 
	 * @param dateFormat
	 *            日期格式
	 * @return 格式化的日期字符串
	 **/
	public static Date getCurrentDate(String dateFormat) {
		if (dateFormat == null || "".equals(dateFormat)) {
			dateFormat = "yyyy-MM-dd HH:mm:ss";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
		Date dDate = null;
		try {
			dDate = sdf.parse(getSysDate(dateFormat));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dDate;
	}

	/**
	 * function:得到按指定格式的系统当前时间<br/>
	 * remark:
	 * 
	 * @return 格式化的日期字符串
	 **/
	public static String getTimeNumber() {
		Calendar CD = Calendar.getInstance();
		int iYY = CD.get(Calendar.YEAR);
		int iMM = CD.get(Calendar.MONTH) + 1;
		int iDD = CD.get(Calendar.DATE);
		int iHH = CD.get(Calendar.HOUR);
		int iNN = CD.get(Calendar.MINUTE);
		int iSS = CD.get(Calendar.SECOND);
		int iMI = CD.get(Calendar.MILLISECOND);

		String strTemp = format(iYY, "%02d") + format(iMM, "%02d")
				+ format(iDD, "%02d") + "-" + format(iHH, "%02d")
				+ format(iNN, "%02d") + format(iSS, "%02d") + "-"
				+ format(iMI, "%03d");
		return strTemp;
	}

	/**
	 * function:得到上周周一的日期<br/>
	 * remark:
	 * 
	 * @return 上周周一日期
	 **/
	public static String getLastMonday() {
		return minusDay(getSysDate("yyyy-MM-dd"), 7 + getWeek() - 1);
	}

	/**
	 * function:得到上周周日的日期<br/>
	 * remark:
	 * 
	 * @return 上周周日日期
	 **/
	public static String getLastSunday() {
		return minusDay(getSysDate("yyyy-MM-dd"), getWeek());
	}

	/**
	 * 将日期字符转换为指定格式日期字符.缺省格式为yyyy-MM-dd<br/>
	 * 
	 * @param dateStr
	 *            日期
	 * @param dateFormat
	 *            日期格式
	 * @return 指定格式的日期
	 **/
	public static String getDateByFormat(String dateStr, String dateFormat) {
		if (dateFormat == null || "".equals(dateFormat)) {
			dateFormat = "yyyy-MM-dd HH:mm:ss";
		}
		String str = "";
		try {
			if (dateStr != null && !"".equals(dateStr)) {
				dateStr = dateStr.replaceAll("年", "-");
				dateStr = dateStr.replaceAll("月", "-");
				dateStr = dateStr.replaceAll("日", "");
				dateStr = dateStr.replaceAll("/", "-");
				java.sql.Date dt = java.sql.Date.valueOf(dateStr);
				SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
				str = sdf.format(dt);
			} else {
				str = "";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str;
	}

	/**
	 * function:日期加天<br/>
	 * remark:
	 * 
	 * @param date
	 *            日期
	 * @param daynum
	 *            天数
	 * @return 日期
	 **/
	public static String plusDay(String date, long daynum) {
		if (date == null || "".equals(date))
			return "";
		java.sql.Date dt = java.sql.Date.valueOf(date);
		long dl = dt.getTime();
		dl = dl + 24 * 60 * 60 * 1000 * daynum;
		java.sql.Date dt2 = new java.sql.Date(dl);
		return dt2.toString();
	}

	/**
	 * function:日期减天<br/>
	 * remark:
	 * 
	 * @param date
	 *            日期
	 * @param daynum
	 *            天数
	 * @return 日期
	 **/
	public static String minusDay(String date, long daynum) {
		if (date == null || "".equals(date))
			return "";
		java.sql.Date dt = java.sql.Date.valueOf(date);
		long dl = dt.getTime();
		dl = dl - 24 * 60 * 60 * 1000 * daynum;
		java.sql.Date dt2 = new java.sql.Date(dl);
		return dt2.toString();
	}

	/**
	 * function:计算日期之间的天数<br/>
	 * remark:
	 * 
	 * @param date1
	 *            被减日期
	 * @param date2
	 *            减的日期
	 * @return 天数
	 **/
	public static long betweenDays(String date1, String date2) {
		if (date1 == null || "".equals(date1) || date2 == null
				|| "".equals(date2))
			return 0;
		java.sql.Date dt1 = java.sql.Date.valueOf(date1);
		java.sql.Date dt2 = java.sql.Date.valueOf(date2);
		long dl = dt1.getTime() - dt2.getTime();
		long daynum = dl / (24 * 60 * 60 * 1000);
		return daynum;
	}

	/**
	 * function:计算六位日期之间的天数<br/>
	 * remark:
	 * 
	 * @param date1
	 *            被减日期
	 * @param date2
	 *            减的日期
	 * @return 天数
	 **/
	public static int betweenDaysSix(String date1, String date2) {
		if (date1 == null || "".equals(date1) || date2 == null
				|| "".equals(date2))
			return 0;
		try {
			date1 = date1.replaceAll("-", "");
			date2 = date2.replaceAll("-", "");
			int d1 = Integer.parseInt(date1);
			int d2 = Integer.parseInt(date2);
			return d2 - d1;
		} catch (Exception e) {
			return 0;
		}

	}

	/**
	 * function:计算六位日期之间的月数<br/>
	 * remark:
	 * 
	 * @param date1
	 * @param date2
	 * @return 月数
	 **/
	public static int betweenMonths(String date1, String date2) {
		int months = 0;
		try {
			int date1_year = (new Integer(date1.substring(0, 4))).intValue();
			int date2_year = (new Integer(date2.substring(0, 4))).intValue();
			int date1_month = (new Integer(date1.substring(5, 7))).intValue();
			int date2_month = (new Integer(date2.substring(5, 7))).intValue();

			if (date1_month > date2_month)
				months = (date1_year - date2_year) * 12
						+ ((new Integer(date1_month - date2_month)).intValue());
			else
				months = (date1_year - date2_year - 1)
						* 12
						+ ((new Integer(date1_month + 12 - date2_month))
								.intValue());
		} catch (Exception e) {

		}
		return months;

	}

	/**
	 * function:得到中文格式的日期<br/>
	 * remark: 如一九七七年八月二十日
	 * 
	 * @return 中文格式日期
	 **/

	public static String getSysChnDate() {
		Calendar date = Calendar.getInstance();
		String year = String.valueOf(date.get(Calendar.YEAR));
		String month = String.valueOf(date.get(Calendar.MONTH) + 1);
		String day = String.valueOf(date.get(Calendar.DAY_OF_MONTH));
		year = year.replaceAll("0", "○");
		year = year.replaceAll("1", "一");
		year = year.replaceAll("2", "二");
		year = year.replaceAll("3", "三");
		year = year.replaceAll("4", "四");
		year = year.replaceAll("5", "五");
		year = year.replaceAll("6", "六");
		year = year.replaceAll("7", "七");
		year = year.replaceAll("8", "八");
		year = year.replaceAll("9", "九");
		if (month.length() < 2) {
			month = month.replaceAll("1", "一");
			month = month.replaceAll("2", "二");
			month = month.replaceAll("3", "三");
			month = month.replaceAll("4", "四");
			month = month.replaceAll("5", "五");
			month = month.replaceAll("6", "六");
			month = month.replaceAll("7", "七");
			month = month.replaceAll("8", "八");
			month = month.replaceAll("9", "九");
		} else {
			month = month.replaceAll("10", "十");
			month = month.replaceAll("11", "十一");
			month = month.replaceAll("12", "十二");
		}
		if (day.length() < 2) {
			day = day.replaceAll("1", "一");
			day = day.replaceAll("2", "二");
			day = day.replaceAll("3", "三");
			day = day.replaceAll("4", "四");
			day = day.replaceAll("5", "五");
			day = day.replaceAll("6", "六");
			day = day.replaceAll("7", "七");
			day = day.replaceAll("8", "八");
			day = day.replaceAll("9", "九");
		} else {
			day = day.replaceAll("10", "十");
			day = day.replaceAll("11", "十一");
			day = day.replaceAll("12", "十二");
			day = day.replaceAll("13", "十三");
			day = day.replaceAll("14", "十四");
			day = day.replaceAll("15", "十五");
			day = day.replaceAll("16", "十六");
			day = day.replaceAll("17", "十七");
			day = day.replaceAll("18", "十八");
			day = day.replaceAll("19", "十九");
			day = day.replaceAll("20", "二十");
			day = day.replaceAll("21", "二十一");
			day = day.replaceAll("22", "二十二");
			day = day.replaceAll("23", "二十三");
			day = day.replaceAll("24", "二十四");
			day = day.replaceAll("25", "二十五");
			day = day.replaceAll("26", "二十六");
			day = day.replaceAll("27", "二十七");
			day = day.replaceAll("28", "二十八");
			day = day.replaceAll("29", "二十九");
			day = day.replaceAll("30", "三十");
			day = day.replaceAll("31", "三十一");

		}
		String sdate = year + "年" + month + "月" + day + "日";
		return sdate;
	}

	/**
	 * function:ISO字符串转成GBK字符串<br/>
	 * remark: ISO字符串
	 * 
	 * @param str
	 * @return GBK字符串
	 **/
	public static String ex_ch(String str) {
		if (str == null) {
			str = "";
		} else {
			try {
				// str = new String(str.getBytes("iso-8859-1"),"gb2312");
				str = new String(str.getBytes("iso-8859-1"), "gbk");
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
		return str.toString();
	}

	/**
	 * function:得到当日星期几<br/>
	 * remark:
	 * 
	 * @return 星期几
	 **/

	public static int getWeek() {
		Calendar cal = Calendar.getInstance();

		int iWeek = cal.get(Calendar.DAY_OF_WEEK) - 1;

		if (iWeek == 0)
			return 7;
		else
			return iWeek;
	}

	/**
	 * function:格式化字符串<br/>
	 * remark: 和C语言的printf功能一样，参数也一样<br/>
	 * 如 %10s, %-10s, %010s,
	 * 
	 * @return 格式化后的字符串
	 **/
	public static String format(String expression, String format) {
		String strFormat;
		String strDest;
		int nRequireLen;
		int nSrcLen;

		int i = format.indexOf('%', 0);

		nSrcLen = expression.length();
		if (i == -1)
			return expression;
		else { // if 1
			strFormat = format.substring(i + 1, format.length() - 1);
			if (strFormat.charAt(0) == '-') // Left align, if 1.1
			{
				try {
					nRequireLen = Integer.parseInt(strFormat.substring(1));
				} catch (Exception e) {
					return expression;
				}

				if (nSrcLen >= nRequireLen) // if 1.11
					return expression;
				else {
					char[] cFill = new char[nRequireLen - nSrcLen];
					Arrays.fill(cFill, 0, nRequireLen - nSrcLen, ' ');
					strDest = expression
							+ new String(cFill, 0, nRequireLen - nSrcLen);
				} // if 1.11

			} // if 1.1
			else // Right align
			{
				try {
					nRequireLen = Integer.parseInt(strFormat.substring(0));
				} catch (Exception e) {
					return expression;
				}

				if (nSrcLen >= nRequireLen) // if 1.11
					return expression;
				else {
					char[] cFill = new char[nRequireLen - nSrcLen];
					if (strFormat.charAt(0) == '0')
						Arrays.fill(cFill, 0, nRequireLen - nSrcLen, '0');
					else
						Arrays.fill(cFill, 0, nRequireLen - nSrcLen, ' ');

					strDest = new String(cFill, 0, nRequireLen - nSrcLen)
							+ expression;
				} // if 1.11
			}// if 1.1
		} // if 1
		return strDest;

	}

	/**
	 * function:格式化整型<br/>
	 * remark:和C语言的printf功能一样，参数也一样
	 * 
	 * @return 格式化后的字符串
	 */
	public static String format(int expression, String format) {
		return format(String.valueOf(expression), format);
	}

	/**
	 * function:格式化长整型<br/>
	 * remark:和C语言的printf功能一样，参数也一样
	 * 
	 * @return 格式化后的字符串
	 **/
	public static String format(long expression, String format) {

		return format(String.valueOf(expression), format);
	}

	/**
	 * function:格式化长整型<br/>
	 * remark:和C语言的printf功能一样，参数也一样
	 * 
	 * @return 格式化后的字符串
	 **/
	public static String format(short expression, String format) {
		return format(String.valueOf(expression), format);
	}

	/**
	 * function:格式化浮点型数据<br/>
	 * remark:和C语言的printf功能一样，参数也一样
	 * 
	 * @return 格式化后的字符串
	 **/
	public static String format(float expression, String format) {
		int nDot = format.indexOf('.', 0);
		int nRequireLen;

		int i = format.indexOf('%', 0);

		String strFormat = format.substring(i, nDot) + "f";

		String strSrc = String.valueOf(expression);

		if (nDot != -1) // if 1
		{
			try {
				nRequireLen = Integer.parseInt(format.substring(nDot + 1,
						format.length() - 1));
				int nSrcDot = String.valueOf(expression).indexOf('.', 0);
				int nSrcDotLen = strSrc.substring(nSrcDot + 1).length();

				if (nSrcDotLen < nRequireLen) // if 1.1
				{
					char[] cFill = new char[nRequireLen - nSrcDotLen];
					Arrays.fill(cFill, 0, nRequireLen - nSrcDotLen, '0');
					strSrc = strSrc
							+ new String(cFill, 0, nRequireLen - nSrcDotLen);
				} // if 1.1

			} catch (Exception e) {
				return strSrc;

			}
		} // if 1
		return format(String.valueOf(strSrc), strFormat);
	}

	/**
	 * function:将Map中的数据转成特点的格式字符串<br/>
	 * remark:字符串格式：field1:value1;field2:value2
	 * 
	 * @return 格式化后的字符串
	 **/
	
	public static String toParamStr(Map paramMap) {
		String strParam = "";
		if ((paramMap == null) || (paramMap.size() <= 0))
			return null;

		for (Iterator iter = paramMap.keySet().iterator(); iter.hasNext();) {
			Object okey = iter.next();
			Object oVal = paramMap.get(okey);
			strParam = strParam + okey + "&#58;" + oVal + "&#59;";
		}
		return strParam;
	}

	/**
	 * function:将特定格式的字符串入到MAP<br/>
	 * remark:字符串格式：field1:value1;field2:value2
	 * 
	 * @return Map形式的数据
	 **/
	public static HashMap toParamMap(String paramStr) {
		HashMap hmParam = new HashMap();
		String strTemp = paramStr;

		strTemp = strTemp.replaceAll("%3A", ":");
		strTemp = strTemp.replaceAll("%3a", ":");
		strTemp = strTemp.replaceAll("%3B", ";");
		strTemp = strTemp.replaceAll("%3b", ";");

		String[] arrParam = strTemp.split(";");

		for (int i = 0; i < arrParam.length; i++) {
			String arrVal[] = arrParam[i].split(":");
			if (arrVal.length <= 1)
				continue;
			System.out.println("param name=" + arrVal[0] + ",param value="
					+ arrVal[1]);
			hmParam.put(arrVal[0], arrVal[1]);
		}
		return hmParam;
	}

	/**
	 * function:取得当月第 一天<br/>
	 * remark:
	 * 
	 * @return 格式化后的字符串
	 */
	public static String getFirstMonthDate(String format) {
		Calendar curCal = Calendar.getInstance();
		curCal.set(Calendar.DAY_OF_MONTH, 1);

		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(curCal.getTime());

	}

	/**
	 * function:取得当月最后一天<br/>
	 * remark:
	 * 
	 * @return 格式化后的字符串
	 */
	public static String getLastMonthDate(String format) {

		Calendar curCal = Calendar.getInstance();
		curCal.set(Calendar.DATE, 1);
		curCal.roll(Calendar.DATE, -1);

		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(curCal.getTime());
	}
	
	/**
	 * 返回当天0:00:00.000
	 * 
	 * @return
	 */
	public static Date getCurrentDate() {
		Date now = new Date();
		return getDateBegin(now);
	}

	public static Date getDateBegin(Date date) {
		if (date == null)
			return null;
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		return c.getTime();
	}

	public static Date getDateEnd(Date date) {
		if (date == null)
			return null;
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		c.set(Calendar.HOUR_OF_DAY, 23);
		c.set(Calendar.MINUTE, 59);
		c.set(Calendar.SECOND, 59);
		c.set(Calendar.MILLISECOND, 000);
		return c.getTime();
	}

	/**
	 * 将数据转为
	 * 
	 * @param serialNBR
	 * @return
	 */
	public static String arrayToString(String[] arr) {
		if (arr.length <= 0) {
			return "";
		}
		String strTemp = "";
		for (int i = 0; i < arr.length; i++) {
			strTemp = strTemp + "," + "'" + arr[i] + "'";
		}
		return strTemp.substring(1);
	}

	/**
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public static boolean isEquals(Object a, Object b) {
		if (a == null || b == null) {
			return a == null && b == null;
		}

		return a.equals(b);
	}

	/**
	 * 数组是否包含某个值
	 * 
	 * @param a
	 * @param b
	 * @return
	 */

	public static boolean containElement(String[] arr, String val) {
		boolean bFlag = false;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i].equals(val)) {
				bFlag = true;
				break;
			}
		}
		return bFlag;
	}

	/**
	 * 数组是否包含某个值
	 * 
	 * @param len
	 * @return
	 */

	public static Long getMaxSerial(int len) {
		String strVal = "9";

		for (int i = 1; i < len; i++) {
			strVal = strVal + "9";
		}

		return Long.valueOf(strVal);
	}

	/**
	 * 转换一个bean为一个map，map的key为bean指定的属性,value为该bean
	 * 
	 * @param bean
	 * @param keyPropName
	 * @return
	 */
	public static Map createBeanMap(Object bean, String keyPropName) {
		Map beanMap = new LinkedHashMap();
		if (bean == null)
			return beanMap;
		try {
			Object key = BeanUtils.getProperty(bean, keyPropName);
			beanMap.put(key, bean);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return beanMap;
	}

	/**
	 * 转换List内容为Map,map的key是集合内对象的指定属性，值为该对象
	 * 
	 * @param clist
	 * @param keyPropName
	 * @return
	 */
	public static List<Map> createBeanMap(List clist, String keyPropName) {
		List<Map> result = new ArrayList<Map>();
		if (clist == null || clist.isEmpty())
			return result;
		for (Object bean : clist) {
			result.add(createBeanMap(bean, keyPropName));
		}
		return result;
	}

	/**
	 * 转换list内容为map,map的key为制定属性的值,map的值为list里面相同key的数据集合list
	 * 
	 * @param clist
	 * @param keyPropName
	 *            list里面对象的属性
	 * @return
	 */
	public static Map createListMap(List clist, String keyPropName) {
		Map<Object, List> beanMap = new LinkedHashMap<Object, List>();

		if (clist == null || clist.isEmpty())
			return beanMap;
		for (Object bean : clist) {
			try {
				Object key = BeanUtils.getProperty(bean, keyPropName);
				// beanMap.put(key, bean);
				boolean flag = false;
				for (Entry<Object, List> entry : beanMap.entrySet()) {
					if (entry.getKey().equals(key)) {
						entry.getValue().add(bean);
						flag = true;
						break;
					}
				}
				if (!flag) {
					List mapList = new ArrayList();
					mapList.add(bean);
					beanMap.put(key, mapList);
				}
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchMethodException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return beanMap;
	}

	/**
	 * 数组转换为map,规则为new Object[key,value,key2,value2]
	 * 
	 * @param arrays
	 * @return
	 */
	public static Map<String, Object> arraysToMap(Object[] arrays) {
		Map<String, Object> queryMap = new HashMap<String, Object>();
		if (arrays == null || arrays.length == 0)
			return queryMap;
		for (int i = 0; i < arrays.length - 1; i++) {
			String key = String.valueOf(arrays[i]);
			if (i + 1 > arrays.length - 1)
				break;
			Object value = arrays[++i];
			queryMap.put(key, value);
		}
		return queryMap;
	}

	/**
	 * 判断param的日期是否在begin 和end 之间 包含
	 * 
	 * @param begin
	 * @param end
	 * @param param
	 * @return
	 */
	public static boolean IsDateBetween(Date begin, Date end, Date param) {
		Calendar c = Calendar.getInstance();
		Calendar b = Calendar.getInstance();
		Calendar e = Calendar.getInstance();

		c.setTime(param == null ? new Date() : param);
		b.setTime(begin == null ? new Date() : begin);
		e.setTime(end == null ? new Date() : end);

		if (c.after(b) && c.before(e)) {
			return true;
		}

		return false;
	}

	public static String fromObj2Str(Object obj) {
		if (obj != null) {
			return obj.toString();
		}
		return "";
	}
	
	public static String fromObj2StrNull(Object obj) {
		if (obj != null) {
			return obj.toString();
		}
		return null;
	}
	
	/**
	 * 取得一个月的最后一天
	 * 
	 * @author daihb
	 * */
	public static Date getLastDayOfMonth(Date oneDate) {
		if (oneDate == null) {
			return oneDate;
		}
		Calendar c = Calendar.getInstance();
		c.setTime(oneDate);
		int lastEndDate = c.getActualMaximum(Calendar.DAY_OF_MONTH);
		c.set(Calendar.DATE, lastEndDate);
		Date lastDate = c.getTime();
		return lastDate;
	}
	
	/**
	 * 
	 * 取得时间范围选择框的内容
	 * @param date
	 * @param scale
	 * @param fromat 暂时只支持”yyyy“年
	 * @return
	 */
	public static List<String> getDateList(Date date,int scale,String format){
		ArrayList<String> result = new ArrayList<String>();
		Calendar cal = Calendar.getInstance();
		if(date==null)date= new Date();
		cal.setTime(date);
		if("yyyy".equals(format)){
			int now = cal.get(Calendar.YEAR);
			for(int i=scale;i>=0;i--){
				int year = now + i; 
				result.add(String.valueOf(year));
			}
			for(int i=1;i<=scale;i++){
				int year = now - i; 
				result.add(String.valueOf(year));
			}
		}else{//TODO month day
			
		}
		return result;
	}
	
	
	
}